package com.itjiange;

import java.util.Arrays;
import java.util.List;

/**
 * 责任链模式：使多个对象都有机会处理请求，从而避免了请求的发送者和接受者之间的耦合关
 * 系。将这些对象连成一条链，并沿着这条链传递该请求，直到有对象处理它为止。
 *
 * @author ItJianGe
 * @data 2024/8/19 10:00
 */
public class ChainMain {
    public static void main(String[] args) {
        // 1. 初始化邮件
        List<Email> emailList = Arrays.asList(new Email(1, "粉丝A"),
                new Email(1, "粉丝B"),
                new Email(2, "诽谤"),
                new Email(3, "我要合作"),
                new Email(99, "垃圾。。。"));

        // 2. 创建邮件处理执行器
        FansEmailProcess fansEmailProcess = new FansEmailProcess();
        SlanderEmailProcess slanderEmailProcess = new SlanderEmailProcess();
        CooperateEmailProcess cooperateEmailProcess = new CooperateEmailProcess();
        GarbageEmailProcess garbageEmailProcess = new GarbageEmailProcess();

        // 3. 构建责任链
        fansEmailProcess.setNextAbstractProcess(slanderEmailProcess);
        slanderEmailProcess.setNextAbstractProcess(cooperateEmailProcess);
        cooperateEmailProcess.setNextAbstractProcess(garbageEmailProcess);

        // 4. 开始处理邮件
        fansEmailProcess.handleMessage(emailList);
    }
}